<?php
/**
 * Header Mission data
 * Title & Description
 * 
 * @package jobs
 * @author Xavier VILAIN
 */
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Hive\Ressource;
use Hive\Mission;
use Fox\Dao\SqlFragment;
use Fox\Generator;
use Fox\Html\TextArea;
use Fox\Html\Input;
use Fox\Html\DropList;
$block = new Fox\Html\Block('bMissionHd',Msg(Hive::BUNDLE,Hive::MISSION_HEADER_DATA));
// Type de Mission
$finder = new Mission\Type();
$types = $finder->find();

$block->add(new DropList(array('mission_type','type'),false,false,true,Mission::TYPE_DEFAULT))
		->size(Input::SIZE_MEDIUM)
		->options($types,	
					Generator::useAttribute('type'),
					Generator::useAttribute('label'));
// Company
$block->add(new Input(array('company','companyName'),true))
		->autocomplete(Generator::url('company','autocomplete'));
// Contact		
$block->add(new Input(array('mission_customer','customer'),true))
		->autocomplete(Generator::url('contacts','autocomplete'),null,'customerid')
		->add(new Input('customerid'))->hidden();
		
// Reference Mission		
$block->add(new Input(array('mission_reference','reference'),true),2)
		->size(Input::SIZE_MEDIUM);
		
// Group
$finder = new Ressource\Group();
$block->add(new DropList(array('contact_group','grouping'),false,false,false),2)
		->options($finder->find(),'grouping','name');
if(!Fox\Authorization\Manager::check(Hive\Ressource::AUTH_GROUP_CAN_CHG)) {
	$block->item('grouping')->input(false);
}
// Mission Statuses
$finder = new Mission\Status();
$block->add(new DropList(array('mission_status','status'),false,false,false),2)
		->options($finder->find(new SqlFragment('language = ?',array(Xview::instance()->language()))),
			'status','label');

// Job Type
$jtFragments[] = new SqlFragment('language = ?',array(Xview::instance()->language()));
$groups = User::current()->groups();
if(count($groups) == 0) {
	
} else {
	$groups[] = 0;
	$jtFragments[] = new SqlFragment('( grouping IN (?) OR grouping IS NULL)',
							array($groups),array(Connection::PARAM_INT_ARRAY));	
	
}
$finder = new Mission\JobType();
$jobtypes = $finder->find(SqlFragment::combine($jtFragments),array('label' => false));
$block->add(new DropList(array('mission_job_type','jobtype'),true,false,true))
		->size(Input::SIZE_MEDIUM)
		->options($jobtypes,	
					Generator::useAttribute('jobtype'),
					Generator::useAttribute('label'));

$block->add(new TextArea(array('mission_description','description'),false))
		->colspan(2)
		->maximize(true);
return $block;